import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 自动化部署子路由
const childrenArr = []
const moduleContext = require.context('./modules', false, /\.js$/)

moduleContext.keys().forEach((fileName) => {
  const moduleConfig = moduleContext(fileName).default
  childrenArr.push(moduleConfig)
})
console.dir(childrenArr)
const routes = [{
  path: '/test',
  component: () => import('../views/TextExamples.vue'),
  children: childrenArr
}]

// 自动化部署子路由
// const modules = {}
// const moduleContext = require.context('./modules', false, /\.js$/)

// moduleContext.keys().forEach((fileName, index, arr) => {
//   const moduleName = arr[index].slice(2, -3)
//   const moduleConfig = moduleContext(fileName).default
//   modules[moduleName] = moduleConfig
// })

const router = new VueRouter({
  routes
})

export default router
